<?php
	require_once("user.inc");
	require_once("project.inc");
	require_once("lib.inc");
	$retVal = array(
		'success' => false,
		'message' => '',
	);	
	$method = getParam('__m');
	$paramArray = getParam('__d');
	if(!is_null($paramArray)){
		$paramArray = json_decode(urldecode($paramArray),true);
	}
	if(!is_null($paramArray) && is_array($paramArray)){
                foreach($paramArray as &$value){
			if(is_array($value)){
				foreach($value as &$item){
					$item = $rwConn->real_escape_string($item);
				}
			}
			else
                        $value = $rwConn->real_escape_string($value);
                }
        }
	$userObj = new User($rwConn);

	$isLoggedInResult = $userObj->isLoggedIn();
	if(!$isLoggedInResult['success']){
		$retVal['message'] = 'You must be logged in.';
                returnAPI($retVal);
	}
	$projectObj = new Project($rwConn,$userObj);
	if(!in_array($method,get_class_methods($projectObj))){
		$retVal['message'] = 'Invalid API call.';
		returnAPI($retVal);
	}

	$methodReturn = $projectObj->$method();
	if(isset($methodReturn['success'])){
		$retVal['success'] = $methodReturn['success'];
		unset($methodReturn['success']);
	}
	if(isset($methodReturn['message'])){
		$retVal['message'] = $methodReturn['message'];
		unset($methodReturn['message']);
	}

	$retVal = array_merge($retVal,$methodReturn);
	returnAPI($retVal);

?>
